﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Web.UI;

namespace ControlExplorer.samples.Sorting
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, System.EventArgs e)
    {
      if (!Page.IsPostBack)
      {
        FpSpread1.DataSource = GetTb_Customers();
        FpSpread1.DataBind();

        ApplyCustomerSeting(FpSpread1.Sheets[0]);
        FpSpread1.ActiveSheetView.AllowSort = true;
        this.FpSpread1.UseClipboard = false;
      }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    private DataSet GetTb_Customers()
    {
      string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb;Persist Security Info=True";
      string sqlstr;

      sqlstr = "SELECT top 20 * FROM Customers";
      DataSet Customers = new DataSet();
      using (OleDbConnection myconn = new OleDbConnection(constr))
      {
        OleDbDataAdapter sqlAdapter1 = new OleDbDataAdapter(sqlstr, myconn);
        sqlAdapter1.Fill(Customers, "Customers");
      }
      return Customers;
    }

    private void ApplyCustomerSeting(FarPoint.Web.Spread.SheetView sheet)
    {
      sheet.SetColumnLabel(0, 0, "ID");
      sheet.SetColumnLabel(0, 1, "公司名称");
      sheet.SetColumnLabel(0, 2, "姓名");
      sheet.SetColumnLabel(0, 3, "标题");
      sheet.SetColumnLabel(0, 4, "地址");
      sheet.SetColumnLabel(0, 5, "城市");
      sheet.SetColumnLabel(0, 6, "地区");
      sheet.SetColumnLabel(0, 7, "邮编");
      sheet.SetColumnLabel(0, 8, "国家");
      sheet.SetColumnLabel(0, 9, "电话");
      sheet.SetColumnLabel(0, 10, "传真");

      sheet.SetColumnWidth(0, 60);
      sheet.SetColumnWidth(1, 210);
      sheet.SetColumnWidth(2, 150);
      sheet.SetColumnWidth(3, 90);
      sheet.SetColumnWidth(4, 185);
      sheet.SetColumnWidth(5, 100);
      sheet.SetColumnWidth(6, 55);
      sheet.SetColumnWidth(7, 75);
      sheet.SetColumnWidth(8, 75);
      sheet.SetColumnWidth(9, 110);
      sheet.SetColumnWidth(10, 110);
    }
  }
}